package com.docman.controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.docman.dao.DocumentDAO;
import com.docman.domainmodel.DocumentBean;
import com.docman.domainmodel.UserBean;


@WebServlet("/SearchServlet")
public class SearchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public SearchServlet() {
        super();
        
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
				
		String search = request.getParameter("search");
		
		ArrayList<DocumentBean> docs = new ArrayList<DocumentBean>();
		
		if((search != null) && (search != "")){
			docs = DocumentDAO.searchFile(search);
			
			request.setAttribute("docList", docs);
			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/searchResult.jsp");

			  if (dispatcher != null){
				  //System.out.println(docs.toString());
			  dispatcher.forward(request, response);

			  }
		}
		else{
			response.sendRedirect("profileServletpath");
		}
		
		
	}

}
